/**
 * Created by ylf on 2018/11/15.
 */
var targetObj;
$(document).ready(function () {
    var form = new xhForm($('#xh_form'));
    $(".form-date").datetimepicker({format: 'yyyy-mm-dd', language: 'zh-CN', autoclose: true});
    form.parse().bindRequired($('#bt_modal_confirm', parent.document));
    $('#bt_modal_confirm', parent.document).click(function () {
        var notlist = "";
        var notarr = "";
        $("input[name='checkbox']:not(:checked)").each(function () {
            notlist += $(this).val() + ",";
            notarr += $(this).attr('default') + ",";
        });
        //获取选中的数据
        var list = "";
        var arr = "";
        $.each($('input:checkbox:checked'), function () {
            list += $(this).val() + ",";
            arr += $(this).attr('default') + ",";
        });
        if (list == "") {
            window.top.swal({
                title: "确定要清空快捷键吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定！",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                closeOnCancel: false
            }).then(function (isConfirm) {
                $.ajax({
                    url: baseUrl + 'short/Person/delShort',
                    data: {tag: notlist, public: notarr},
                    type: 'POST',
                    success: function (data) {
                        window.top.swal(
                            '操作成功',
                            '',
                            'success'
                        );
                        window.top.xhTop.closeModal();
                        window.top.xhTop.getActiveFrame().$('#personloads').attr('src', window.top.xhTop.getActiveFrame().$('#personloads').attr('src'));
                    },
                    error: function (data) {
                        window.top.swal(
                            data.responseJSON.error,
                            '',
                            'error'
                        );
                    }
                });
            });
        }
        else {
            if (notlist == "") {
            }
            else {
                $.ajax({
                    url: baseUrl + 'short/Person/delShort',
                    data: {tag: notlist, public: notarr},
                    type: 'POST',
                    success: function (data) {

                    },
                    error: function (data) {
                        window.top.swal(
                            data.responseJSON.error,
                            '',
                            'error'
                        );
                    }
                });
            }

            $.ajax({
                url: baseUrl + 'short/Person/updateShort',
                data: {tag: list, public: arr},
                type: 'POST',
                success: function (data) {
                    window.top.swal(
                        '操作成功',
                        '',
                        'success'
                    );
                    window.top.xhTop.closeModal();
                    window.top.xhTop.getActiveFrame().$('#personloads').attr('src', window.top.xhTop.getActiveFrame().$('#personloads').attr('src'));
                },
                error: function (data) {
                    window.top.swal(
                        data.responseJSON.error,
                        '',
                        'error'
                    );
                }
            });

        }


    });


    $('div li').click(function () {
        if (!$(this).hasClass("select")) {
            $(this).addClass("select");
            $(this).find('input').prop('checked', true);
            $(this).find('input').attr('checked', true);
        } else {
            $(this).removeClass("select");
            $(this).find('input').attr("checked", false);
        }
    });


});
